﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Nvigorate.Data.Query;

namespace Nvigorate.Test.Common
{
    /// <summary>
    /// Summary description for CriterionTests
    /// </summary>
    [TestClass]
    public class CriterionTests
    {
        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext { get; set; }

        #region Additional test attributes

        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test 
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //

        #endregion

        [TestMethod]
        public void TestEqualsForValuesList()
        {
            var x = Criterion.Equals("AccountId", 1);
            var y = Criterion.Equals("AccountId", 1);

            Assert.AreEqual(x, y);
        }

        // New stuff
        #region TDD ATTACK! OH SNAPPIZIFICATION!

        //public enum Comparisons
        //{
        //    Between,
        //    Equal,
        //    Greater,
        //    GreaterOrEqual,
        //    Less,
        //    LessOrEqual,
        //    Like,
        //    In,
        //    InFunction,
        //    NotEqual,
        //    Substring
        //}

        [TestMethod]
        public void BetweenCriterionFactories()
        {
            var criterion = Criterion.Column("column", "table").Between((Literal) "lower").And((Literal) "upper");

            Assert.IsInstanceOfType(criterion, typeof(Between));
            Assert.IsInstanceOfType(criterion.Field, typeof(Column));

            Criterion.Column("column", "table").Between((Literal) 1).And((Literal) 10);
            Criterion.Property("property").Between(Column.Named("Column1").OwnedBy("Table")).And(Column.Named("Column2").OwnedBy("Table"));
            Criterion.Literal(10).Between(Column.Named("Column1").OwnedBy("Table")).And(Column.Named("Column2").OwnedBy("Table"));
            Criterion.Column("column", "table").Between((Literal) "01/01/2009").And(Function.GetDate());
            Criterion.Property("property").Between(Function.UDF("").Parameters((Literal) "test", (Literal) 1, (Literal) DateTime.Now)).And((Literal) 10);
            Criterion
                .Literal("thingamajig")
                .Between(
                Select.Query(
                    Table.From("table"),
                    Select.Column("column"),
                    Where.Criteria(Criterion.Column("id", "table").EqualTo((Literal) "1"))))
                .And((Literal) 39);
        }
        [TestMethod]
        public void EqualCriterionFactories()
        {

            //Equals
            Criterion.Column("column", "table").EqualTo((Literal)"value");
            Criterion.Column("column", "table").EqualTo((Literal)10);
            Criterion.Property("property").EqualTo(Column.Named("Column").OwnedBy("Table"));
            Criterion.Literal(10).EqualTo(Column.Named("Column").OwnedBy("Table"));
            Criterion.Column("column", "table").EqualTo(Function.GetDate());
            Criterion.Property("property").EqualTo(Function.UDF("").Parameters((Literal)"test", (Literal)1, (Literal)DateTime.Now));
            Criterion
                .Literal("thingamajig")
                .EqualTo(
                    Select.Query(
                        Table.From("table"),
                        Select.Column("column"),
                        Where.Criteria(Criterion.Column("id", "table").EqualTo((Literal)"1"))));

            //Greater
            

            //GreaterOrEqual

            //Less

            //LessOrEqual

            //Like

            //In

            //NotEqual

        }

        

        #endregion

        
    }


}